//
//  MenuView.swift
//  MyTest
//
//  Created by guanzhongwang on 2021/4/10.
//

import UIKit

class MenuView: UIView {

    /*
    // Only override draw() if you perform custom drawing.
    // An empty implementation adversely affects performance during animation.
    override func draw(_ rect: CGRect) {
        // Drawing code
    }
    */
    var closure:(()->Void)?
    init(_ title:String ,imageName:String,isRed:Bool = false,closure:@escaping (()->Void)) {
        super.init(frame: CGRect.zero)
        backgroundColor = .white
        let image = UIImageView()
        addSubview(image)
        image.snp.makeConstraints({
            $0.top.equalTo(15)
            $0.centerX.equalToSuperview()
        })
       
        var img = UIImage(named: imageName)
        

        if isRed{
            img = img?.withRenderingMode(UIImage.RenderingMode.alwaysTemplate)
            image.tintColor = RED_COLOR
        }
        image.image = img
        
        let label = UILabel()
        label.text = title
        addSubview(label)
        label.font = Font_Size_10
        label.textColor = .black
        label.textAlignment = .center
        label.snp.makeConstraints({
            $0.top.equalTo(image.snp.bottom).offset(5)
            $0.bottom.equalToSuperview().inset(15)
            $0.centerX.equalToSuperview()
        })
        let tgr = UITapGestureRecognizer.init(target: self, action: #selector(click))
        addGestureRecognizer(tgr)
        self.closure = closure
    }
    
    @objc func click(){
        self.closure?()
    }
    required init?(coder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
    
}
